#include <LiquidCrystal.h>

const int rs = 3, en = 5, d4 = 10, d5 = 11, d6 = 12, d7 = 13;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
char arr [9]= {'a', 'b', 'c', 'd' ,'e' ,'f' ,'g', 'h', 'i'};

int trigPin = 7;
int echoPin = 8;
long duration, cm, inches;
char buf[16];

void setup() {
  // put your setup code here, to run once:
  lcd.begin(16, 2);
  //lcd.print("hey, please fuck me hard.");

  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  memset(buf, 0x00, sizeof(buf));
  delay(1000);
}

void loop() {
  // put your main code here, to run repeatedly:
    //lcd.setCursor(0, 1);
    //int pos;

    digitalWrite(trigPin, LOW);
    delayMicroseconds(5);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);

    duration = pulseIn(echoPin,HIGH);
    cm = (duration/2) / 29.1;
    sprintf(buf, "%ld cm", cm);
    lcd.print(buf);
    Serial.print(cm);
    Serial.print("cm");
    Serial.println();
    delay(1000);
    lcd.clear();

    /*for (pos=0; pos<13; pos++) {
      lcd.scrollDisplayLeft();
      delay(600);
    }
    for (pos=0; pos<29; pos++) {
      lcd.scrollDisplayRight();
      delay(600);
    }
    for (pos=0; pos<16; pos++) {
      lcd.scrollDisplayLeft();
      delay(600);
    }
    delay(1000);
    lcd.setCursor(0, 1);
    */

}
